package com.rf.richfitwheel.sysbill.controller;


import com.rf.richfitwheel.admin.utils.UserUtil;
import com.rf.richfitwheel.sysbill.model.SysCustomerAccount;
import com.rf.richfitwheel.sysbill.service.SysCustomerAccountService;
import com.rf.richfitwheel.utils.PageJson;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author wangTao
 * @since 2024-06-17
 */
@RestController
@RequestMapping("/sysbill/sysCustomerAccount")
@Api(tags = "基础数据设置--客商信息",description = "提供客商信息的相关的API",value = "sysCustomerAccount类")
public class SysCustomerAccountController {

    @Autowired
    private SysCustomerAccountService sysCustomerAccountService;

    /**
     * 通过ID查询信息
     *
     * @param id
     * @return
     */
    @GetMapping("/detail/{id}")
    @ApiOperation(value = "根据ID查询单条客商信息")
    public SysCustomerAccount detail(@ApiParam(name = "id",required = true)@PathVariable("id") String id) {
        QueryWrapper<SysCustomerAccount> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", id);
        SysCustomerAccount sysCustomerAccount = sysCustomerAccountService.getOne(queryWrapper);
        return sysCustomerAccount;
    }

    @GetMapping("/deleteOne/{id}")
    @ApiOperation(value = "根据ID查询删除单条客商信息")
    public Boolean deleteOne(@ApiParam(name = "id",required = true)@PathVariable("id") String id) {
        return sysCustomerAccountService.removeById(id);
    }

    /**
     * 分页查询信息
     *
     * @param
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "客商数据根据条件分页查询信息")
    public PageJson getPageList(@RequestBody SysCustomerAccount sysCustomerAccount) {
        PageJson pageJson = sysCustomerAccountService.pageJson(sysCustomerAccount);
        return pageJson;
    }

    /**
     * 添加
     *
     * @param sysCustomerAccount
     * @return
     */
    @PostMapping("/add")
    @ApiOperation(value = "客商数据信息新增")
    public boolean save(@RequestBody SysCustomerAccount sysCustomerAccount) {
        //账户状态 1:启用 2:停用   新添加的默认是启用
        sysCustomerAccount.setAccountStatus("1");
        //创建人
        sysCustomerAccount.setCreateName(UserUtil.getUser().getStaffName());
        return sysCustomerAccountService.save(sysCustomerAccount);
    }

    /**
     * 修改
     *
     * @param sysCustomerAccount
     * @return
     */
    @PostMapping("/modify")
    @ApiOperation(value = "客商数据信息修改")
    public boolean modify(@RequestBody SysCustomerAccount sysCustomerAccount) {
        return sysCustomerAccountService.updateById(sysCustomerAccount);
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @PostMapping("/del")
    @ApiOperation(value = "客商数据信息多条删除")
    public boolean delBatch(@ApiParam(name = "ids",required = true) @RequestParam("ids") List<String> ids) {
        return sysCustomerAccountService.removeByIds(ids);
    }
}
